package com.kanshu.ksgb.fastread.doudou.common.security;

import android.text.TextUtils;

/**
 * 加解密管理器
 *
 * @author wanchunyang
 */
public class SecretManager {

    private ISecurity mSecurity;

    private volatile static SecretManager sInstance;

    private static final String TAG = SecretManager.class.getSimpleName();

    private SecretManager() {
        mSecurity = new MyAES();
    }

    public static SecretManager getInstance() {
        synchronized (SecretManager.class) {
            if (sInstance == null) {
                sInstance = new SecretManager();
            }
        }
        return sInstance;
    }

    public String encrypt(String src) {
        if (TextUtils.isEmpty(src)) {
            return src;
        }
        try {
            return mSecurity.encrypt(src);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return src;
    }

    public String decrypt(String src) {
        if (TextUtils.isEmpty(src)) {
            return "";
        }
        try {
            return mSecurity.decrypt(src);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return src;
    }


    /**
     * 清楚本地key
     * void
     */
    public void clear() {
        if (mSecurity != null) {
            mSecurity.clear();
        }
    }

}
